package com.lry.basic.metrics;

import java.util.Collections;
import java.util.function.Supplier;

public class CompactGauge <T extends Number> implements Gauge<T>{

    private final Id id;
    private final Supplier<T> supplier;

    private final Clock clock;


    public CompactGauge(Id id, Supplier<T> supplier) {
        this(id, supplier, SystemClock.INSTANCE);
    }

    public CompactGauge(Id id, Supplier<T> supplier, Clock clock) {
        this.id = id;
        this.supplier = supplier;
        this.clock = clock;
    }

    @Override
    public T get() {
        return supplier.get();
    }

    @Override
    public Id getId() {
        return id;
    }

    @Override
    public Iterable<Measurement> measure() {
        return Collections.singletonList(new Measurement(id,clock.getCurrentMilliseconds(),get().doubleValue()));
    }
}
